﻿@{
    ViewBag.Title = "选择分类";

}
@section styles{
    <link href="~/static/css/Ztree.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/metroStyle.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/public.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/client.css" type="text/css" rel="stylesheet" />
}
<style>
    a {
        text-decoration: none;
    }
</style>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">@ViewBag.Title</div>
                <div class="layui-card-body layui-col-md6">
                    <div class="demoTable">
                        <div class="layui-inline">
                            <input class="layui-input" name="keyword" id="pname" placeholder="分类名称" autocomplete="off">
                        </div>
                        <button class="layui-btn search" data-type="reload" data-isparent="true">搜索</button>
                    </div>
                    <table class="layui-hide layui-table" id="layui-table1" lay-filter="Event"></table>
                </div>
                <div class="layui-card-body layui-col-md6">
                    <div class="demoTable">
                        <div class="layui-inline">
                            <input class="layui-input" name="keyword" id="cname" placeholder="分类名称" autocomplete="off">
                        </div>
                        <button class="layui-btn search" data-type="reload" data-isparent="false">搜索</button>
                    </div>
                    <table class="layui-hide layui-table" id="layui-table2" lay-filter="Event"></table>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <input type="hidden" id="productType" value="" />
        <button class="layui-btn" id="Next" type="button">下一步</button>
    </div>
</div>
<div id="Layer_ajax"></div>
@section scripts{
    @*
        <script src="~/Theme/js/content.min.js?v=1.0.0"></script>*@
    <script src="~/static/js/jquery.ztree.core.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.excheck.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.exedit.js" type="text/javascript"></script>

    @*
        <script src="~/Theme/js/plugins/layer/laydate/laydate.js"></script>*@
    <script type="text/javascript">
        var tableH = $(".layui-table-container").height();
        layui.use(['form', 'layedit', 'laydate', 'tree', 'table', 'layer', 'element', 'upload'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , table = layui.table
                , upload = layui.upload;

            table.render({
                elem: "#layui-table1",
                url: '/ShopType/GetShopTypeList',
                cellMinWidth: 26,
                cols: [[
                    { field: 'typeName', title: '分类名称', event: 'setSign' },
                    //{ title: '操作', width: 120, align: 'center', toolbar: '#barDemo' }
                ]],
                id: "table1",
                //limits: [1, 2, 3, 5, 6],
                page: false,
                done: function (res, curr, count) {
                    if (res.data.length > 0) {
                        var id = res.data[0].id;
                        table.render({
                            elem: "#layui-table2",
                            url: '/ShopType/GetShopTypeList2',
                            where: { id: id },
                            cellMinWidth: 26,
                            cols: [[
                                { field: 'typeName', title: '分类名称', event: 'select' },
                            ]],
                            id: "table2",
                            page: false,
                            done: function (res, curr, count) { 
                                $('.layui-form.layui-border-box.layui-table-view').eq(1).find('td:first').click();
                            }
                        });
              
                        //$('.layui-table tbody tr td:first').click();
                    }
                }
            });

            table.on('tool(Event)', function (obj) {
                var data = obj.data;
                if (obj.event === 'setSign') {
                    table.reload('table2', {
                        where: {
                            id: data.id,
                        }
                    })
                } else if (obj.event === 'select') {
                    $("#productType").val(data.id);
                }
            });
            $(".search").on('click', function () {
                var isparent = $(this).data('isparent');
                if (isparent) {
                    table.reload('table1', {
                        where: { keyword: $('#pname').val() }
                    })
                } else {
                    table.reload('table2', {
                        where: { keyword: $('#cname').val() }
                    })
                }
            });

            $("#Next").on("click", function () {
                var id = $("#productType").val();
                if (id == null || id == "") {
                    layer.msg("请先选择一个分类");
                    return false;
                }
                window.location = "/Commodity/Create?typeid="+id;
            });
            function LayerOpen(title, url) {
                var open = layer.open({
                    type: 2,
                    title: title,
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['600px', '450px'],
                    content: url,
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index)//确定两个页面的父子关系
                    },
                    end: function () {
                        //销毁后重新加载
                        table.reload('table1', {
                        })
                    }
                });
            }
        });


        $("#layui-Area").click(function () {
            $(".layui-Area .layui-Area-hide").toggleClass("layui-Area-show")
            $(this).parent(".layui-form-select").toggleClass("layui-form-selected");
        });

        $(".layui-Area").mouseleave(function () {
            $(".layui-Area .layui-Area-hide").removeClass("layui-Area-show")
        })

    </script>
}
